import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'
export default class Footer extends Component {
	static propTypes = {
		checkAllTodo: PropTypes.func.isRequired,
	}
	//全选和取消全选操作
	checkedAll = (event) => {
		this.props.checkAllTodo(event.target.checked)
	}
    //清除所有已经完成的todo
    handleClearAllDone=()=>{
        this.props.clearAllDone()
    }
	render() {
		const { todos } = this.props
		//统计已完成的数量
		const doneCount = todos.reduce(
			(pre, current) => pre + (current.done ? 1 : 0),
			0
		)
		//全部数量
		const total = todos.length
		return (
			<div className="todo-footer">
				<label>
					<input
						type="checkbox"
						checked={doneCount === total&&total!==0 ? true : false}
						onChange={this.checkedAll}
					/>
				</label>
				<span>
					<span>已完成{doneCount}</span> / 全部{total}
				</span>
				<button  onClick={this.handleClearAllDone} className="btn btn-danger">清除已完成任务</button>
			</div>
		)
	}
}
